﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WinServer
{
    /// 第四步、接收过滤器工厂(ReceiveFilterFactory)
    /// 接收过滤器工厂(ReceiveFilterFactory)用于为每个会话创建接收过滤器. 定义一个过滤器工厂(ReceiveFilterFactory)类型, 你必须实现接口 IReceiveFilterFactory. 类型参数 "TRequestInfo" 是你要在整个程序中使用的请求类型

    public class HansReceiveFilterFactory : SuperSocket.SocketBase.Protocol.IReceiveFilterFactory<HansRequestInfo>
    {   

        /// 字符编码

        public Encoding Encoder = Encoding.GetEncoding("gbk");

        /// 开始标记 如："!Start"    
        public string StartMark = "!Start";  
        /// 结束标记 如："$End"
        public string EndMark = "$End";

        public HansReceiveFilterFactory(Encoding encoder, string startMark, string endMark)
        {

            Encoder = encoder;

            StartMark = startMark;

            EndMark = endMark;

        }

        public SuperSocket.SocketBase.Protocol.IReceiveFilter<HansRequestInfo> CreateFilter(SuperSocket.SocketBase.IAppServer appServer, SuperSocket.SocketBase.IAppSession appSession, System.Net.IPEndPoint remoteEndPoint)

        {

            return new HansReceiveFilter(Encoder, StartMark, EndMark);

        }
    }
}
